package com.chainyoung.common.appcommon.db;

import io.realm.DynamicRealm;
import io.realm.FieldAttribute;
import io.realm.RealmMigration;
import io.realm.RealmSchema;

public class DbMigrationFirst implements RealmMigration {


    @Override
    public void migrate(DynamicRealm realm, long oldVersion, long newVersion) {
        RealmSchema schema = realm.getSchema();
        if (oldVersion == 1) {
            schema.create("HdWalletTokenCache")
                    .addField("address", String.class)
                    .addField("contractAddress", String.class, FieldAttribute.PRIMARY_KEY)
                    .addField("tokenName", String.class)
                    .addField("tokenSymbol", String.class)
                    .addField("balance", String.class)
                    .addField("banlanceCny", String.class)
                    .addField("balanceEth", String.class);
            oldVersion++;
        }
        if (oldVersion==2){
            schema.get("HdWalletCache")
                    .addField("isMainWallet", boolean.class);
            oldVersion++;
        }
    }

}
